{include file="public/header"/}
<script src="{__PUBLIC_PATH}/common/js/jquery.js?v={$version}"></script>
<script src="{__PUBLIC_PATH}/admin/pcf/global.js?v={$version}"></script>
</head>
<body>
<div class="layui-fluid" style="padding-bottom:83px;border:0;" id="LAY-component-layer-list">
    <div class="layui-card">
        <div class="layui-card-body table-tool-mini">
            <div class="layui-form toolbar">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <button data-type="add" class="layui-btn icon-btn"><i class="layui-icon">&#xe654;</i>添加</button>
                        <button data-type="batch_del" data-url="{:url('/task/del')}" class="layui-btn layui-btn-danger icon-btn"><i class="layui-icon"></i>删除</button>
                    </div>
                </div>
            </div>
            <table class="layui-table" id="tableUser" lay-filter="tableUser"></table>
        </div>
        <div style="clear:both;"></div>
    </div>
</div>
<script type="text/html" id="tableBarUser">
    <a class="layui-btn layui-btn-primary layui-btn-xs" data-type="edit" data-id="{{d.id}}">编辑</a>
</script>
{include file="public/footer"/}
<script>
    layui.use(['layer', 'form', 'table', 'admin'], function () {
        var $ = layui.jquery;
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var admin = layui.admin;
        // 渲染表格
        var insTb = table.render({
            elem: '#tableUser',
            url: "{:url('/task/index')}",
            page: true,
            cellMinWidth: 100,
            cols: [[
                {type:'checkbox'},
                {field:'id',title:'ID',align: 'center',width:60},
                {field: 'content', title: '执行内容',align: 'center'},
                {field: 'title', title: '任务标题',align: 'center'},
                {field: 'maxnum', title: '最多执行',width: 100,align: 'center'},
                {field: 'start_time', title: '开始时间', align: 'center'},
                {field: 'stop_time', title: '结束时间', align: 'center'},
                {field: 'add_time', title: '创建时间', align: 'center'},
                {field: 'num', title: '执行次数',width: 100,align: 'center'},
                {field: 'update_time', title: '最后执行时间',align: 'center'},
                {toolbar: '#tableBarUser', title: '操作', minWidth: 100,align: 'center', }
            ]]
        });

        $(document).on("click","#LAY-component-layer-list .layui-btn",function(){
          var type = $(this).data('type');
          active[type] && active[type].call(this);
        });

        //触发事件
        var active = {
            add: function(){
                layer.open({
                    type: 2,
                    title: '添加任务',
                    fixed: true,
                    shadeClose: false,
                    shade: 0.3,
                    area: ['100%', '100%'],
                    content: '{:url("/task/add")}'
                });
            },
            edit: function(){
                var obj = this;
                var id = $(obj).attr('data-id');
                layer.open({
                    type: 2,
                    title: '修改任务',
                    fixed: true,
                    shadeClose: false,
                    shade: 0.3,
                    area: ['100%', '100%'],
                    content: '{:url("/task/edit")}?id='+id
                });
            },
            batch_del: function(){
                var checkRows = table.checkStatus('tableUser');
                if (checkRows.data.length === 0) {
                    layer.msg('请选择要删除的数据', {icon: 2,time:1000});
                    return;
                }
                var ids = checkRows.data.map(function (d) {
                    return d.id;
                });
                batch_del(this, ids);
            }
        };

    });
</script>
</body>
</html>